/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.psdk;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.ApplicationInfo;
import android.text.TextUtils;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.Vector;
import org.json.JSONArray;
import org.json.JSONObject;

public class h {
    private static String a = "QData";
    private static String b = "";

    public static void a(Context paramContext, String paramString1, String paramString2) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        localSharedPreferences.edit().putString(paramString1, paramString2).commit();
    }

    public static void a(Context paramContext, String paramString, long paramLong) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        localSharedPreferences.edit().putLong(paramString, paramLong).commit();
    }

    public static void a(Context paramContext, String paramString, boolean paramBoolean) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        localSharedPreferences.edit().putBoolean(paramString, paramBoolean).commit();
    }

    public static String b(Context paramContext, String paramString1, String paramString2) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        return localSharedPreferences.getString(paramString1, paramString2);
    }

    public static boolean b(Context paramContext, String paramString, boolean paramBoolean) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        return localSharedPreferences.getBoolean(paramString, paramBoolean);
    }

    public static long b(Context paramContext, String paramString, long paramLong) {
        SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
        return localSharedPreferences.getLong(paramString, paramLong);
    }

    public static String a(Context paramContext, String paramString) {
        String str = "";
        str = a(paramContext);
        if ("qch_default".equals(str)) {
            SharedPreferences localSharedPreferences = paramContext.getSharedPreferences("qhopen_game_session_info", 0);
            str = localSharedPreferences.getString("channel", paramString);
        }
        else if ((str.length() == 16) && (str.startsWith("qch_" + n.n()))
                && (n.j() + n.k().equals(n.a(str.substring(10))))) {
            k.a = true;
            str = "";
        }
        return str;
    }

    public static String a(Context paramContext) {
        try {
            if (!(TextUtils.isEmpty(b)))
                return b;
            String str1 = paramContext.getApplicationInfo().sourceDir;
            if (TextUtils.isEmpty(str1))
                break label114;
            String str2 = s.a(str1);
            if (TextUtils.isEmpty(str2))
                break label114;
            if ((str2.startsWith("err")) && (str2.length() > "err".length()))
                str2 = "qch_" + "default" + str2.substring("err".length());
            if (TextUtils.isEmpty(str2))
                break label114;
            b = str2;
            return b;
        } catch (Exception localException) {
            com.qihoo.psdk.util.h.a(a, localException);
        }
        label114: return "qch_default";
    }

    public static String b(Context paramContext, String paramString) {
        String str = "";
        try {
            JSONObject localJSONObject1 = new JSONObject();
            j localj = new j(paramContext, paramString);
            JSONObject localJSONObject2 = localj.a();
            localJSONObject1.put("header", localJSONObject2);
            str = localJSONObject1.toString();
            str = n.c(str);
        } catch (Exception localException) {
            com.qihoo.psdk.util.h.a(a, localException);
        } catch (Error localError) {
            com.qihoo.psdk.util.h.a(a, localError);
        }
        return str;
    }

    public static synchronized String c(Context paramContext, String paramString1, String paramString2) {
        String str1 = "";
        try {
            if (TextUtils.isEmpty(paramString2))
                paramString2 = a;
            String str2 = n.b(n.n(paramContext));
            str2 = n.d(str2);
            d locald = new d();
            locald.a(str2);
            JSONObject localJSONObject1 = new JSONObject();
            JSONObject localJSONObject2 = null;
            JSONArray localJSONArray = null;
            JSONObject localJSONObject3 = null;
            c localc = null;
            if ((i.a != null) && (i.a.size() > 0)) {
                localJSONObject2 = new JSONObject();
                localJSONArray = new JSONArray();
                for (int i = 0; i < i.a.size(); ++i) {
                    localc = (c) i.a.get(i);
                    localJSONObject3 = localc.a();
                    if (localJSONObject3 == null)
                        continue;
                    localJSONArray.put(localJSONObject3);
                }
            }
            if (locald.a != null) {
                localObject1 = locald.a.entrySet().iterator();
                localObject2 = null;
                while (((Iterator) localObject1).hasNext()) {
                    localObject3 = (Map.Entry) ((Iterator) localObject1).next();
                    String str3 = (String) ((Map.Entry) localObject3).getKey();
                    localObject2 = (Vector) ((Map.Entry) localObject3).getValue();
                    if (localJSONArray == null) {
                        localJSONObject2 = new JSONObject();
                        localJSONArray = new JSONArray();
                    }
                    for (int j = 0; j < ((Vector) localObject2).size(); ++j) {
                        localc = (c) ((Vector) localObject2).get(j);
                        localJSONObject3 = localc.a();
                        if (localJSONObject3 == null)
                            continue;
                        localJSONArray.put(localJSONObject3);
                    }
                }
            }
            if ((localJSONArray != null) && (localJSONArray.length() > 0) && (localJSONObject2 != null))
                localJSONObject2.put(n.k(paramContext), localJSONArray);
            if ((localJSONObject2 != null) && (localJSONObject2.length() > 0))
                localJSONObject1.put("event", localJSONObject2);
            Object localObject1 = new j(paramContext, paramString1);
            Object localObject2 = ((j) localObject1).a();
            localJSONObject1.put("header", localObject2);
            str1 = localJSONObject1.toString();
            Object localObject3 = n.n(paramContext);
            com.qihoo.psdk.util.h.a(paramString2, "logFile: " + ((String) localObject3));
            com.qihoo.psdk.util.h.a(paramString2, "logData: " + str1);
            str1 = n.c(str1);
            n.a((String) localObject3, str1);
            i.a();
            locald.a();
        } catch (Exception localException) {
            com.qihoo.psdk.util.h.a(a, localException);
        } catch (Error localError) {
            com.qihoo.psdk.util.h.a(a, localError);
        }
        return ((String) (String) (String) str1);
    }
}